package com.bigknow.appstore.web.framework.util;

/**
 * Created by Administrator on 2015/3/26.
 */
public final class Assert {
public static void assertNotNull(Object obj,Class<? extends RuntimeException> e) {
        if(obj==null){
            try {
                throw e.newInstance();
            } catch (Exception ee) {
                ee.printStackTrace();
                throw new RuntimeException();
            }
        }
    }

    public static void assertNotNull(Object obj){
        if(obj==null) throw new NullPointerException();
    }

    public static void assertNotNull(Object obj,String info){
        if(obj==null) throw new NullPointerException(info);
    }

    public static void assertInteger(Object obj){
        assertInteger(obj,"["+obj.toString()+"] is not int");
    }


    public static void assertInteger(Object obj, String info){
        assertNotNull(obj,info);
        if(obj instanceof Integer) return;
        if(obj instanceof String){
            try{
                Integer.parseInt((String)obj);
            }catch(Exception e ){
                throw new RuntimeException(info!=null?info:"");
            }
        }
    }

    public static void assertNotNullString(String str,String info){
        if(str==null||"".equals(str)){
            throw new NullPointerException(info!=null?info:"");
        }
    }

    public static void assertNotNullString(String str){
        assertNotNullString(str,null);
    }
}
